<?php

namespace App\Http\Middleware;

use App\Models\User;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class CheckAdmin
{
    public function handle(Request $request, Closure $next, ...$guards)
    {
        $user_id = Auth::id();
        $user_role = User::find($user_id)->user_roles()->where('role_id', 1)->first();
        if (isset($user_role->role_id) && $user_role->role_id == 1) {
            return $next($request);
        }

        abort(422, "您不具备权限");
    }
}
